{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "6d1ca9ac",
   "metadata": {},
   "source": [
    "<a href=\"https://colab.research.google.com/github/run-llama/llama_index/blob/main/docs/examples/llm/bedrock.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9e3a8796-edc8-43f2-94ad-fe4fb20d70ed",
   "metadata": {},
   "source": [
    "# Oracle Cloud Infrastructure Generative AI\n",
    "\n",
    "Oracle Cloud Infrastructure (OCI) Generative AI is a fully managed service that provides a set of state-of-the-art, customizable large language models (LLMs) that cover a wide range of use cases, and which is available through a single API.\n",
    "Using the OCI Generative AI service you can access ready-to-use pretrained models, or create and host your own fine-tuned custom models based on your own data on dedicated AI clusters. Detailed documentation of the service and API is available __[here](https://docs.oracle.com/en-us/iaas/Content/generative-ai/home.htm)__ and __[here](https://docs.oracle.com/en-us/iaas/api/#/en/generative-ai/20231130/)__.\n",
    "\n",
    "This notebook explains how to use OCI's Genrative AI embedding models with LlamaIndex."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3802e8c4",
   "metadata": {},
   "source": [
    "## Setup\n",
    "\n",
    "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb0dd8c9",
   "metadata": {},
   "outputs": [],
   "source": [
    "%pip install llama-index-embeddings-oci-genai"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "544d49f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install llama-index"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c2921307",
   "metadata": {},
   "source": [
    "You will also need to install the OCI sdk"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "378d5179",
   "metadata": {},
   "outputs": [],
   "source": [
    "!pip install -U oci"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03d4024a",
   "metadata": {},
   "source": [
    "## Basic Usage\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "60be18ae-c957-4ac2-a58a-0652e18ee6d6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from llama_index.embeddings.oci_genai import OCIGenAIEmbeddings\n",
    "\n",
    "embedding = OCIGenAIEmbeddings(\n",
    "    model_name=\"cohere.embed-english-light-v3.0\",\n",
    "    service_endpoint=\"https://inference.generativeai.us-chicago-1.oci.oraclecloud.com\",\n",
    "    compartment_id=\"MY_OCID\",\n",
    ")\n",
    "\n",
    "e1 = embedding.get_text_embedding(\"This is a test document\")\n",
    "print(e1[-5:])\n",
    "\n",
    "e2 = embedding.get_query_embedding(\"This is a test document\")\n",
    "print(e2[-5:])\n",
    "\n",
    "docs = [\"This is a test document\", \"This is another test document\"]\n",
    "e3 = embedding.get_text_embedding_batch(docs)\n",
    "print(e3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
